package com.ztom.daily.n2022.m4;

import java.util.Arrays;

/**
 * 旋转函数
 * <p>
 * https://leetcode-cn.com/problems/rotate-function/
 *
 * @author ZhangTao
 */
public class Day22MaxRotateFunction {

    public int maxRotateFunction(int[] nums) {
        int f = 0;
        int n = nums.length;
        int numSum = Arrays.stream(nums).sum();
        for (int i = 0; i < n; i++) {
            f += i * nums[i];
        }
        int res = f;
        for (int i = n - 1; i > 0; i--) {
            f += numSum - n * nums[i];
            res = Math.max(res, f);
        }
        return res;
    }
}
